﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TEAA;

public partial class CreateDatabase : System.Web.UI.Page
{
    SystemManager sm;
    //XmlFileManager xfm;

    protected void Page_Load(object sender, EventArgs e)
    {
        Session["page"] = "CreateDatabase";
        if (IsPostBack)
        {

        }
        else
        {
            ((SiteMaster)Master).fillddlDatabase();
            ((SiteMaster)Master).setddlDatabaseSelectedItem();
        }
    }

    protected void ButtonCreateDB_Click(object sender, EventArgs e)
    {
        String name = TextBoxDB.Text.ToString();
        if (verifyDBName(name))
        {            
            sm = SystemManager.GetSystemManager();
            try
            {
                sm.CreateDatabase(TextBoxDB.Text.ToString());
                LabelHelytelenABNev.Visible = false;
                //LabelHelyesABNev.Visible = true;
                TextBoxDB.Text = "";
                ((SiteMaster)Master).fillddlDatabase();                
            }
            catch (Exception ex)
            {
                Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
                string errorMessage = "";
                Exception exception = ex;
                while (exception != null)
                {
                    errorMessage += exception.Message + "\\n";
                    exception = exception.InnerException;
                }
                Response.Write("alert('" + errorMessage + "');");
                Response.Write("</script>");
            }
        }
        else
        {
            LabelHelytelenABNev.Visible = true;
        }

    }

    public Boolean verifyDBName(String name)
    {
        if (name.Equals("") || name.Contains(" ") || name.Contains("   ")) return false;
        else return true;
    }

}
